const MongoClient = require('mongodb').MongoClient;
const url = "mongodb://taosha_user:apyl8XWP6LSW4JHs@101.35.6.34:27722/taosha";

async function main() {
  const client = await MongoClient.connect(url, {useNewUrlParser: true, useUnifiedTopology: true});
  const db = client.db('taosha');


  let topics = await db.collection('topics')
    .find(
      {author_name: '抽屉新热榜', content: /zhihu.com/}
    )
    .toArray();


  for (let i = 0; i < topics.length; i++) {
    try {
      let topic = topics[i];
      let result = await db.collection('topics').updateOne({_id: topic._id}, {
        $set: {
          author_id: '620899babc0e87448a243aad',
          author_name: '知乎推荐',
          author_avatar: '/public/images/zhihu.png',
          boards: ['抽屉'],
          tags: ['抽屉']
        },
      });
      console.log(result.result, i, topics.length);
    } catch (e) {
      console.warn(e.message, i, topics.length);
    }
  }

  client.close();

}

main();
